#include<ros/ros.h>
#include<std_msgs/Float32.h>

float a=0.0,b=0.0;

void callback_a(const std_msgs::Float32& cmd_a)
{
    a=cmd_a.data;
}

void callback_b(const std_msgs::Float32& cmd_b)
{
    b=cmd_b.data;
}

int main(int argc, char** argv)
{
    ros::init(argc,argv,"q3_1b");
    ros::NodeHandle n;
    ros::Subscriber sub_a=n.subscribe("send_2a",1000,callback_a);
    ros::Subscriber sub_b=n.subscribe("send_2b",1000,callback_b);
    // 设置循环频率
    ros::Rate rate(2); // 2Hz 500ms
    while(ros::ok())
    {
        std_msgs::Float32 c;
        c.data=a+b;
        ROS_INFO("c=%f", c.data);
        ros::spinOnce();
        rate.sleep();
    }
    return 0;
}